"""
资金相关模型
"""

from jlpay.model.base import OrgBaseReq, BaseResponse


# ==================== 延期资金管控查询 ====================
class DeferredActivationQueryRequest(OrgBaseReq):
    """延期资金管控查询请求"""
    
    API_PREFIX = "/open/fund/deferred/activation"
    API_URI = "/query"
    
    def __init__(self):
        """初始化延期资金管控查询请求"""
        super().__init__()
        # merch_no 继承自 OrgBaseReq


class DeferredActivationQueryResponse(BaseResponse):
    """延期资金管控查询响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化延期资金管控查询响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.status = None
        self.open_time = None
        self.close_time = None
        
        if response_dict:
            self.status = response_dict.get('status')
            self.open_time = response_dict.get('open_time')
            self.close_time = response_dict.get('close_time')


# ==================== 延期资金管控开通 ====================
class DeferredActivationOpenRequest(OrgBaseReq):
    """延期资金管控开通请求"""
    
    API_PREFIX = "/open/fund/deferred/activation"
    API_URI = "/open"
    
    def __init__(self):
        """初始化延期资金管控开通请求"""
        super().__init__()
        self.agreement_pic = None
    
    def set_agreement_pic(self, agreement_pic):
        """
        设置协议图片
        
        Args:
            agreement_pic: 协议图片
            
        Returns:
            DeferredActivationOpenRequest实例
        """
        self.agreement_pic = agreement_pic
        return self


class DeferredActivationOpenResponse(BaseResponse):
    """延期资金管控开通响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化延期资金管控开通响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        # 只包含 ret_code 和 ret_msg，继承自 BaseResponse


# ==================== 延期资金管控关停 ====================
class DeferredActivationCloseRequest(OrgBaseReq):
    """延期资金管控关停请求"""
    
    API_PREFIX = "/open/fund/deferred/activation"
    API_URI = "/close"
    
    def __init__(self):
        """初始化延期资金管控关停请求"""
        super().__init__()
        # merch_no 继承自 OrgBaseReq


class DeferredActivationCloseResponse(BaseResponse):
    """延期资金管控关停响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化延期资金管控关停响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        # 只包含 ret_code 和 ret_msg，继承自 BaseResponse


# ==================== 资金流水查询 ====================
class FundFlowQueryRequest(OrgBaseReq):
    """资金流水查询请求"""
    
    API_PREFIX = "/open/fund/deferred/order"
    API_URI = "/query"
    
    def __init__(self):
        """初始化资金流水查询请求"""
        super().__init__()
        self.out_order_id = None
    
    def set_out_order_id(self, out_order_id):
        """
        设置外部订单ID
        
        Args:
            out_order_id: 外部订单ID
            
        Returns:
            FundFlowQueryRequest实例
        """
        self.out_order_id = out_order_id
        return self


class FundFlowQueryResponse(BaseResponse):
    """资金流水查询响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化资金流水查询响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.out_order_id = None
        self.ori_out_order_id = None
        self.transaction_id = None
        self.merch_no = None
        self.order_type = None
        self.freeze_amount = None
        self.unfreeze_amount = None
        self.status = None
        self.failure_reason = None
        self.freeze_time = None
        self.unfreeze_time = None
        self.reason = None
        self.remark = None
        
        if response_dict:
            self.out_order_id = response_dict.get('out_order_id')
            self.ori_out_order_id = response_dict.get('ori_out_order_id')
            self.transaction_id = response_dict.get('transaction_id')
            self.merch_no = response_dict.get('merch_no')
            self.order_type = response_dict.get('order_type')
            self.freeze_amount = response_dict.get('freeze_amount')
            self.unfreeze_amount = response_dict.get('unfreeze_amount')
            self.status = response_dict.get('status')
            self.failure_reason = response_dict.get('failure_reason')
            self.freeze_time = response_dict.get('freeze_time')
            self.unfreeze_time = response_dict.get('unfreeze_time')
            self.reason = response_dict.get('reason')
            self.remark = response_dict.get('remark')


# ==================== 资金冻结 ====================
class FundFreezeRequest(OrgBaseReq):
    """资金冻结请求"""
    
    API_PREFIX = "/open/fund/deferred/order"
    API_URI = "/freeze"
    
    def __init__(self):
        """初始化资金冻结请求"""
        super().__init__()
        self.out_order_id = None
        self.transaction_id = None
        self.freeze_amount = None
        self.reason = None
        self.remark = None
    
    def set_out_order_id(self, out_order_id):
        """
        设置外部订单ID
        
        Args:
            out_order_id: 外部订单ID
            
        Returns:
            FundFreezeRequest实例
        """
        self.out_order_id = out_order_id
        return self
    
    def set_transaction_id(self, transaction_id):
        """
        设置交易ID
        
        Args:
            transaction_id: 交易ID
            
        Returns:
            FundFreezeRequest实例
        """
        self.transaction_id = transaction_id
        return self
    
    def set_freeze_amount(self, freeze_amount):
        """
        设置冻结金额
        
        Args:
            freeze_amount: 冻结金额
            
        Returns:
            FundFreezeRequest实例
        """
        self.freeze_amount = freeze_amount
        return self
    
    def set_reason(self, reason):
        """
        设置冻结原因
        
        Args:
            reason: 冻结原因
            
        Returns:
            FundFreezeRequest实例
        """
        self.reason = reason
        return self
    
    def set_remark(self, remark):
        """
        设置备注
        
        Args:
            remark: 备注
            
        Returns:
            FundFreezeRequest实例
        """
        self.remark = remark
        return self


class FundFreezeResponse(BaseResponse):
    """资金冻结响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化资金冻结响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        # 只包含 ret_code 和 ret_msg，继承自 BaseResponse


# ==================== 资金解冻 ====================
class FundUnfreezeRequest(OrgBaseReq):
    """资金解冻请求"""
    
    API_PREFIX = "/open/fund/deferred/order"
    API_URI = "/unfreeze"
    
    def __init__(self):
        """初始化资金解冻请求"""
        super().__init__()
        self.out_order_id = None
        self.ori_out_order_id = None
        self.unfreeze_amount = None
        self.reason = None
        self.remark = None
    
    def set_out_order_id(self, out_order_id):
        """
        设置外部订单ID
        
        Args:
            out_order_id: 外部订单ID
            
        Returns:
            FundUnfreezeRequest实例
        """
        self.out_order_id = out_order_id
        return self
    
    def set_ori_out_order_id(self, ori_out_order_id):
        """
        设置原外部订单ID
        
        Args:
            ori_out_order_id: 原外部订单ID
            
        Returns:
            FundUnfreezeRequest实例
        """
        self.ori_out_order_id = ori_out_order_id
        return self
    
    def set_unfreeze_amount(self, unfreeze_amount):
        """
        设置解冻金额
        
        Args:
            unfreeze_amount: 解冻金额
            
        Returns:
            FundUnfreezeRequest实例
        """
        self.unfreeze_amount = unfreeze_amount
        return self
    
    def set_reason(self, reason):
        """
        设置解冻原因
        
        Args:
            reason: 解冻原因
            
        Returns:
            FundUnfreezeRequest实例
        """
        self.reason = reason
        return self
    
    def set_remark(self, remark):
        """
        设置备注
        
        Args:
            remark: 备注
            
        Returns:
            FundUnfreezeRequest实例
        """
        self.remark = remark
        return self


class FundUnfreezeResponse(BaseResponse):
    """资金解冻响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化资金解冻响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        # 只包含 ret_code 和 ret_msg，继承自 BaseResponse


# ==================== 资金续冻 ====================
class FundRefreezeRequest(OrgBaseReq):
    """资金续冻请求"""
    
    API_PREFIX = "/open/fund/deferred/order"
    API_URI = "/refreeze"
    
    def __init__(self):
        """初始化资金续冻请求"""
        super().__init__()
        self.out_order_id = None
        self.ori_out_order_id = None
        self.reason = None
        self.remark = None
    
    def set_out_order_id(self, out_order_id):
        """
        设置外部订单ID
        
        Args:
            out_order_id: 外部订单ID
            
        Returns:
            FundRefreezeRequest实例
        """
        self.out_order_id = out_order_id
        return self
    
    def set_ori_out_order_id(self, ori_out_order_id):
        """
        设置原外部订单ID
        
        Args:
            ori_out_order_id: 原外部订单ID
            
        Returns:
            FundRefreezeRequest实例
        """
        self.ori_out_order_id = ori_out_order_id
        return self
    
    def set_reason(self, reason):
        """
        设置续冻原因
        
        Args:
            reason: 续冻原因
            
        Returns:
            FundRefreezeRequest实例
        """
        self.reason = reason
        return self
    
    def set_remark(self, remark):
        """
        设置备注
        
        Args:
            remark: 备注
            
        Returns:
            FundRefreezeRequest实例
        """
        self.remark = remark
        return self


class FundRefreezeResponse(BaseResponse):
    """资金续冻响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化资金续冻响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        # 只包含 ret_code 和 ret_msg，继承自 BaseResponse 